//package com.shop.loan.util;
//
//import cn.hutool.core.date.DateUtil;
//import cn.hutool.core.util.NumberUtil;
//import cn.hutool.http.HttpUtil;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.github.pagehelper.PageHelper;
//import com.shop.loan.mapper.*;
//import com.shop.loan.model.*;
//import com.shop.loan.model.common.Code;
//import com.shop.loan.model.common.ResResult;
//import com.shop.loan.model.entity.*;
//import com.shop.loan.model.enums.*;
//import com.shop.loan.model.vo.ContractCodeVo;
//import com.shop.loan.model.vo.PlatformAuthVo;
//import com.shop.loan.oss.UCloudUtil;
//import com.shop.loan.rentaldata.RentalDataUtil;
//import com.shop.loan.service.*;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Lazy;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//import xyz.erupt.annotation.model.Column;
//import xyz.erupt.annotation.model.Row;
//import xyz.erupt.annotation.query.Condition;
//import xyz.erupt.jpa.dao.EruptDao;
//import xyz.erupt.upms.service.EruptUserService;
//
//import javax.annotation.Resource;
//import javax.persistence.Query;
//import javax.transaction.Transactional;
//import java.math.BigDecimal;
//import java.time.LocalDateTime;
//import java.util.*;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
//@Slf4j
//@Component
//public class OrderUtil {
//
//    @Value("${sys.requestUrl}")
//    private String requestUrl;
//
//    @Value("${erupt.upload-path}")
//    private String filePath;
//
//    @Resource
//    EruptDao eruptDao;
//
//    @Resource
//    UserOrderByMybatisMapper userOrderByMybatisMapper;
//
//    @Resource
//    BusinessByMybatisMapper businessByMybatisMapper;
//
//    @Resource
//    RentalUserByMybatisMapper rentalUserByMybatisMapper;
//
//    @Resource
//    OrderPayLogByMybatisMapper orderPayLogByMybatisMapper;
//
//    @Resource
//    OrderLogisticsByMybatisMapper orderLogisticsByMybatisMapper;
//
//    @Resource
//    EruptUserByMybatisMapper eruptUserByMybatisMapper;
//
//    @Resource
//    EruptUserService eruptUserService;
//
//    @Resource
//    UCloudUtil uCloudUtil;
//
//    @Resource
//    ESignUtil eSignUtil;
//
//    @Lazy
//    @Resource
//    Util util;
//
//    @Resource
//    OrderSignByMybatisMapper orderSignByMybatisMapper;
//
//    @Lazy
//    @Resource
//    OrderService orderService;
//
//    @Resource
//    BusinessService businessService;
//
//    @Lazy
//    @Resource
//    RentalUserService rentalUserService;
//
//    @Resource
//    AlipayUtil alipayUtil;
//
//    @Resource
//    WxUtil wxUtil;
//
//    @Resource
//    AlipayOrderByMybatisMapper alipayOrderByMybatisMapper;
//
//    @Resource
//    OrderAuthByMybatisMapper orderAuthByMybatisMapper;
//
//    @Resource
//    ESignService eSignService;
//
//    @Resource
//    SettingService settingService;
//
//    @Resource
//    BusinessUtil businessUtil;
//
//    @Resource
//    RentalDataUtil rentalDataUtil;
//
//    /**
//     * 物流签收后操作
//     */
//    @Transactional
//    public void logisticsSignature(long id) throws Exception {
//        Setting setting = settingService.getSetting();
//        Order userOrder = eruptDao.queryEntity(Order.class, "id = :id", new HashMap<String, Object>(1) {
//            {
//                this.put("id", id);
//            }
//        });
//
//        if (userOrder.getType() == 1) {
//            //直接购买 签收则订单结束
//            userOrder.setStatus(OrderStatus.end.getStatus());
//        } else {
//            //订单状态修改为待履约
//            userOrder.setStatus(OrderStatus.rent_ing.getStatus());
//            //应付款时间
//            if (userOrder.getDayNum() != null && userOrder.getDayNum() > 0) {
//                userOrder.setPayTime(DateUtil.offsetDay(new Date(), userOrder.getDayNum() - 1));
//            } else {
//                userOrder.setPayTime(DateUtil.offsetDay(new Date(), setting.getSignPayTime() - 1));
//            }
//        }
//
//        /**
//         * 首款转支付
//         */
////        pledgeToPay(userOrder);
//
//        /**
//         * 判断是否前置收费
//         */
//        checkIsBefore(userOrder);
//
//        /**
//         * 冻结金额解冻
//         */
//        businessUtil.unfreezeBalance(userOrder.getId(), userOrder.getBusiness().getId());
//
//    }
//
//
////    public void pledgeToPay(UserOrder userOrder) {
////        //首款转支付
////        if (userOrder.getPledgeMoneyStatus() && userOrder.getPledgeMoney().doubleValue() > 0) {
////            userOrder.setPayMoney(userOrder.getPayMoney().add(userOrder.getPledgeMoney()));
////
////            AlipayOrderByMybatis alipayOrderByMybatis = orderService.getAlipayOrderByPledge(userOrder.getId());
////
////            //增加一条还款记录
////            OrderPayLogByMybatis orderPayLog = new OrderPayLogByMybatis();
////            orderPayLog.setOrderId(userOrder.getId());
////            orderPayLog.setPayOrderId(alipayOrderByMybatis.getTradeNo());
////            orderPayLog.setPayTime(new Date());
////            orderPayLog.setRemark("首款");
////            orderPayLog.setMoney(alipayOrderByMybatis.getReceiptAmount());
////            orderPayLog.setType(1);
////            if (userOrder.getBusiness() != null) {
////                orderPayLog.setBusinessId(userOrder.getBusiness().getId());
////            }
////            orderPayLogByMybatisMapper.insertSelective(orderPayLog);
////        }
////    }
//
//    /**
//     * 判断是否前置收费 若是则扣除余额
//     *
//     * @param userOrder
//     */
//    public void checkIsBefore(Order userOrder) {
//        Business business = userOrder.getBusiness();
//        if (business != null && business.getIsBefore() != null && business.getIsBefore()) {
//            BigDecimal totalPrice = userOrder.getPrice();
//            if (userOrder.getScreenMoneyStatus() && userOrder.getScreenMoney().doubleValue() > 0) {
//                totalPrice = totalPrice.add(userOrder.getScreenMoney());
//            }
//            BigDecimal platformNum = totalPrice.multiply(business.getBrokerageRate()
//                    .divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_DOWN));
//            //商户余额扣除一笔金额
//            AddCBalanceVo addCBalanceVo = new AddCBalanceVo();
//            addCBalanceVo.setPlatformNumber(BigDecimal.ZERO);
//            addCBalanceVo.setNumber(platformNum);
//            addCBalanceVo.setBalanceType(BusinessBalanceType.order.getStatus());
//            addCBalanceVo.setIsAdd(false);
//            addCBalanceVo.setFreezeStatus(true);
//            addCBalanceVo.setRentalUserId(userOrder.getRentalUser().getId());
//            addCBalanceVo.setUseType(BusinessBalanceUseType.platform_charge.getType());
//            addCBalanceVo.setOrderId(userOrder.getId());
//            addCBalanceVo.setRemark("订单收费");
//            boolean status = businessService.updateCBalance(addCBalanceVo, business.getId());
//            if (status) {
//                BusinessBalanceLogByCredit businessBalanceLog = new BusinessBalanceLogByCredit();
//                businessBalanceLog.setAfterMoney(BigDecimal.ZERO);
//                businessBalanceLog.setBeforeMoney(BigDecimal.ZERO);
//                businessBalanceLog.setBalanceType(addCBalanceVo.getBalanceType());
//                businessBalanceLog.setIsAdd(true);
//                businessBalanceLog.setRemark(addCBalanceVo.getRemark());
//                businessBalanceLog.setNumber(BigDecimal.ZERO);
//                businessBalanceLog.setPlatformNumber(platformNum);
//                businessBalanceLog.setCreateTime(LocalDateTime.now());
//                businessBalanceLog.setBusiness(business);
//                businessBalanceLog.setFreezeStatus(addCBalanceVo.getFreezeStatus());
//                businessBalanceLog.setOrderId(addCBalanceVo.getOrderId());
//                businessBalanceLog.setRentalUser(userOrder.getRentalUser());
//                businessBalanceLog.setUseType(addCBalanceVo.getUseType());
//                eruptDao.getEntityManager().persist(businessBalanceLog);
//            }
//        }
//    }
//
//    /**
//     * 订单拒绝
//     *
//     * @param userOrder
//     * @param platformAuthVo
//     * @param eruptUserId
//     */
//    public void rejectOrder(Order userOrder, PlatformAuthVo platformAuthVo, Long eruptUserId) {
//        userOrder.setWillStatus(platformAuthVo.getWillStatus() == null ? false : platformAuthVo.getWillStatus());
//        try {
//            if (userOrder.getStatus() == 1) {
//                /**
//                 * 审核中的订单 进行退款
//                 */
//                AlipayOrderByMybatis alipayOrderByMybatis = orderService.getAlipayOrderByPledge(userOrder.getId());
//                BigDecimal backMoney = BigDecimal.ZERO;
//                if (alipayOrderByMybatis != null) {
//                    if (alipayOrderByMybatis.getPFrom() != null && alipayOrderByMybatis.getPFrom().trim().equals(WxUtil.pFrom)) {
//                        wxUtil.payBack(alipayOrderByMybatis.getTradeNo(), alipayOrderByMybatis.getReceiptAmount(), alipayOrderByMybatis.getReceiptAmount());
//                    } else {
//                        alipayUtil.payBack(alipayOrderByMybatis.getTradeNo(), alipayOrderByMybatis.getReceiptAmount());
//                    }
//                    backMoney = backMoney.add(alipayOrderByMybatis.getReceiptAmount());
//                }
//                //查看是否有碎屏金额
//                List<AlipayOrderByMybatis> screenList = alipayOrderByMybatisMapper.selectOrderByScreen(userOrder.getId(), "TRADE_SUCCESS");
//                if (screenList != null && screenList.size() > 0) {
//                    AlipayOrderByMybatis screenOrder = screenList.get(0);
//                    if (screenOrder.getPFrom() != null && screenOrder.getPFrom().trim().equals(WxUtil.pFrom)) {
//                        wxUtil.payBack(screenOrder.getTradeNo(), screenOrder.getReceiptAmount(), screenOrder.getReceiptAmount());
//                    } else {
//                        alipayUtil.payBack(screenOrder.getTradeNo(), screenOrder.getReceiptAmount());
//                    }
//                    backMoney = backMoney.add(screenOrder.getReceiptAmount());
//                }
//                userOrder.setBackMoney(backMoney);
//            }
//            userOrder.setStatus(OrderStatus.platform_reject.getStatus());
//
//            //若有电子牵 则撤销
//            OrderSignByMybatis orderSignByMybatis = orderSignByMybatisMapper.selectByOrderId(userOrder.getId());
//            if (orderSignByMybatis != null && orderSignByMybatis.getSignFlowId() != null) {
//                eSignUtil.revoke(orderSignByMybatis.getSignFlowId());
//            }
//
//            if (platformAuthVo.getUserStatus() != null && !platformAuthVo.getUserStatus()) {
//                User rentalUser = eruptDao.queryEntity(User.class, "id = :id", new HashMap<String, Object>(1) {
//                    {
//                        this.put("id", userOrder.getRentalUser().getId());
//                    }
//                });
//                if (rentalUser != null) {
//                    rentalUser.setUserStatus(false);
//                }
//            }
//            if (eruptUserId != null) {
//                //增加一条审核记录
//                OrderAuthByMybatis orderAuthByMybatis = new OrderAuthByMybatis();
//                orderAuthByMybatis.setOrderId(userOrder.getId());
//                orderAuthByMybatis.setCreateTime(new Date());
//                orderAuthByMybatis.setReason("机审");
//                orderAuthByMybatis.setCreateUserId(eruptUserId);
//                orderAuthByMybatis.setAuthStatus(false);
//                orderAuthByMybatis.setOrderStatus(2);
//                orderAuthByMybatisMapper.insertSelective(orderAuthByMybatis);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            log.error(Util.GetErrorDetails(e));
//        }
//    }
//
//    /**
//     * 替换合同中的标识
//     *
//     * @param contract
//     * @param contractCodeVo
//     * @return
//     */
//    public static String getContractFill(String contract, ContractCodeVo contractCodeVo) {
//        JSONObject codeJs = JSON.parseObject(JSON.toJSONString(contractCodeVo));
//        if (contract.contains("$")) {
//            String patternString = "\\$\\{(.+?)\\}";
//            Pattern pattern = Pattern.compile(patternString);
//            Matcher matcher = pattern.matcher(contract);
//            String text = contract;
//            while (matcher.find()) {
//                String keyString = matcher.group(1);
//                String value = codeJs.getString(keyString);
//                value = value == null ? "" : value;
//                text = matcher.replaceFirst(value);
//                matcher = pattern.matcher(text);
//            }
//            return text;
//        }
//        return contract;
//    }
//
//
//    /**
//     * 填充订单和用户信息
//     *
//     * @param orderContracts
//     * @param orderId
//     * @param rentalUserId
//     */
//    public void setOrderContractUser(Set<OrderContract> orderContracts, Long orderId, Long rentalUserId) {
//        if (orderContracts == null) {
//            return;
//        }
//        for (OrderContract orderContract : orderContracts) {
//            orderContract.setOrderId(orderId);
//            orderContract.setRentalUserId(rentalUserId);
//        }
//    }
//
//    /**
//     * 填充权益和用户信息
//     *
//     * @param orderCardRightsSet
//     * @param orderId
//     * @param rentalUserId
//     */
//    public void setOrderCardRights(Set<OrderCardRights> orderCardRightsSet, Long orderId, Long rentalUserId) {
//        if (orderCardRightsSet == null) {
//            return;
//        }
//        for (OrderCardRights orderCardRights : orderCardRightsSet) {
//            orderCardRights.setOrderId(orderId);
//            orderCardRights.setRentalUserId(rentalUserId);
//        }
//    }
//
//
//    /**
//     * 填充订单和用户信息
//     *
//     * @param orderAttachments
//     * @param orderId
//     */
//    public void setOrderAttachmentsUser(Set<OrderAttachment> orderAttachments, Long orderId) {
//        if (orderAttachments == null) {
//            return;
//        }
//        for (OrderAttachment orderContract : orderAttachments) {
//            orderContract.setOrderId(orderId);
//        }
//    }
//
//    /**
//     * 填充订单和用户信息
//     *
//     * @param logisticsSet
//     * @param orderId
//     */
//    public void setOrderLogistics(Set<Logistics> logisticsSet, Long orderId) {
//        if (logisticsSet == null) {
//            return;
//        }
//        for (Logistics logistics : logisticsSet) {
//            logistics.setOrderId(orderId);
//        }
//    }
//
//    /**
//     * 设置订单列表显示数据处理
//     *
//     * @param list
//     */
//    public void setOrderData(Collection<Map<String, Object>> list) {
//        for (Map map : list) {
//            Long id = Long.valueOf(map.get("id").toString());
//            //设置屏幕险
//            if (map.get("screenMoney") != null) {
//                BigDecimal screenMoney = new BigDecimal(map.get("screenMoney").toString());
//                if (screenMoney.doubleValue() > 0) {
//                    if (map.get("screenMoneyStatus") != null && Boolean.valueOf(map.get("screenMoneyStatus").toString())) {
//                        map.put("screenMoney", screenMoney + "（已支付）");
//                    } else {
//                        map.put("screenMoney", screenMoney + "（未支付）");
//                    }
//                }
//            }
//            //押金是否支付
//            if (map.get("pledgeMoney") != null) {
//                BigDecimal screenMoney = new BigDecimal(map.get("pledgeMoney").toString());
//                if (screenMoney.doubleValue() > 0) {
//                    if (map.get("pledgeMoneyStatus") != null && Boolean.valueOf(map.get("pledgeMoneyStatus").toString())) {
//                        map.put("pledgeMoney", screenMoney + "（已支付）");
//                    } else {
//                        map.put("pledgeMoney", screenMoney + "（未支付）");
//                    }
//                }
//            }
//            //规格信息
//            if (map.get("goodsSizeInfo") != null) {
//                map.put("goods_name", map.get("goods_name") + "【" + map.get("goodsSizeInfo") + "】");
//            }
//
//            if (map.get("createTime") != null) {
//                String createTime = map.get("createTime").toString();
//                if (createTime != null && NumberUtil.isLong(createTime)) {
//                    map.put("createTime", DateUtil.formatDateTime(DateUtil.date(Long.parseLong(createTime))));
//                }
//            }
//
//            if (map.get("orderLocation") != null) {
//                String orderLocation = map.get("orderLocation").toString();
//                if (StringUtils.hasLength(orderLocation)) {
//                    //查询该下单定位订单数量
//                    Integer orderNum = userOrderByMybatisMapper.selectNumByLocation(orderLocation);
//                    if (orderNum != null && orderNum >= 2) {
//                        map.put("orderLocation", orderLocation + "【" + orderNum + "】");
//                    }
//                }
//            }
//
//            //用户手机号码
//            UserOrderByMybatis userOrderByMybatis = userOrderByMybatisMapper.selectOrderById(id);
//            if (map.get("rentalUser_mobile") != null) {
//                map.put("rentalUser_mobile", userOrderByMybatis.getRentalUser_name() + "【" + map.get("rentalUser_mobile").toString() + "】");
//
//                Integer orderNum = userOrderByMybatisMapper.selectCountByUser(userOrderByMybatis.getRentalUserId());
//                if (orderNum != null && orderNum >= 2) {
//                    map.put("rentalUser_mobile", map.get("rentalUser_mobile") + "【" + orderNum + "】");
//                }
//            }
//
//            map.put("zhiMaScore", userOrderByMybatis.getZhiMaScore());
//            map.put("baoStatus", userOrderByMybatis.getBaoStatus());
//        }
//    }
//
//    /**
//     * 订单列表统计
//     */
//    public List<Row> setOrderStatistic(List<Condition> conditions, String sqlEx) {
//        //行对象
//        List<Row> rows = new ArrayList<>();
//
//        Long businessId = null, serviceEruptUserId = null;
//        EruptUserByMybatis eruptUserByMybatis = eruptUserByMybatisMapper.selectByPrimaryKey(eruptUserService.getCurrentUid());
//        if (eruptUserByMybatis != null && eruptUserByMybatis.getBusinessId() != null) {
//            //商户管理员
//            businessId = eruptUserByMybatis.getBusinessId();
//        } else if (!eruptUserByMybatis.getIsAdmin()) {
//            //如果不是超管 只能查看自己领取的订单
//            serviceEruptUserId = eruptUserService.getCurrentUid();
//        }
//        String tableAsName = "u_order";
//
//        String sqlExStr = getSqlByOrderCondition(conditions, tableAsName);
//        if (StringUtils.hasLength(sqlEx)) {
//            sqlExStr = sqlExStr + " and " + sqlEx;
//        }
//
//        if (businessId != null && businessId > 0) {
//            sqlExStr = sqlExStr + " and business_id=" + businessId;
//        }
//        if (serviceEruptUserId != null && serviceEruptUserId > 0) {
//            sqlExStr = sqlExStr + " and (auth_service_id=" + serviceEruptUserId
//                    + " or after_service_id=" + serviceEruptUserId + " or overdue_service_id=" + serviceEruptUserId + ")";
//        }
//
//        List<Long> userIds = rentalUserService.getUserIdBySearch();
//        String userIdStr = null;
//        if (userIds != null && userIds.size() > 0) {
//            userIdStr = org.apache.commons.lang3.StringUtils.join(userIds, ",");
//        }
//        if (StringUtils.hasLength(userIdStr)) {
//            sqlExStr = sqlExStr + " and " + tableAsName + ".rental_user_id in (" + userIdStr + ")";
//        }
//
//        if (StringUtils.hasLength(sqlExStr) && !sqlExStr.startsWith("and") && !sqlExStr.startsWith(" and")) {
//            sqlExStr = " and " + sqlExStr;
//        }
//        Query totalMoneyQuery = eruptDao.getEntityManager().createNativeQuery(
//                "select sum(price) as number from s_uses_order as u_order where is_delete = false " + sqlExStr);
//
//        Query payMoneyQuery = eruptDao.getEntityManager().createNativeQuery(
//                "select sum(pay_money) as number from s_uses_order as u_order where is_delete = false " + sqlExStr);
//
//        Query screenMoneyMoneyQuery = eruptDao.getEntityManager().createNativeQuery(
//                "select sum(screen_money) as number from s_uses_order as u_order where is_delete = false and screen_money_status = 1 " + sqlExStr);
//
//        Query discountsMoneyMoneyQuery = eruptDao.getEntityManager().createNativeQuery(
//                "select sum(discounts_money) as number from s_uses_order as u_order where is_delete = false and screen_money_status = 1 " + sqlExStr);
//
//
//        Query overdueMoneyQuery = eruptDao.getEntityManager().createNativeQuery(
//                "select sum(u_order.price - u_order.pay_money) as number " +
//                        "from s_uses_order as u_order " +
//                        " where u_order.is_delete = false and u_order.status > 4 and u_order.now_overdue = false " + sqlExStr);
//        Object total = totalMoneyQuery.getResultList().get(0);
//        total = total == null ? "0" : total;
//        Object pay = payMoneyQuery.getResultList().get(0);
//        pay = pay == null ? "0" : pay;
//        Object screen = screenMoneyMoneyQuery.getResultList().get(0);
//        screen = screen == null ? "0" : screen;
//        Object overdue = overdueMoneyQuery.getResultList().get(0);
//        overdue = overdue == null ? "0" : overdue;
//        Object discounts = discountsMoneyMoneyQuery.getResultList().get(0);
//        discounts = discounts == null ? "0" : discounts;
//
//
//        //列对象
//        List<Column> totalColumns = new ArrayList<>();
//        totalColumns.add(Column.builder().value("").colspan(1).build());
//        totalColumns.add(Column.builder().value("订单总额：" + total).colspan(1).className("text-green").build());
//        totalColumns.add(Column.builder().value("付款总额：" + pay).colspan(1).className("text-green").build());
//        totalColumns.add(Column.builder().value("优惠金额：" + discounts).colspan(1).className("text-green").build());
//
//        List<Column> payColumns = new ArrayList<>();
//        payColumns.add(Column.builder().value("").colspan(1).build());
//        payColumns.add(Column.builder().value("碎屏总额：" + screen).colspan(1).className("text-green").build());
//        payColumns.add(Column.builder().value("逾期总额：" + overdue).colspan(1).className("text-red").build());
//        rows.add(Row.builder().columns(totalColumns).build());
//        rows.add(Row.builder().columns(payColumns).build());
//        if (conditions != null) {
//            Long authServiceUserId = null;
//            for (Condition condition : conditions) {
//                if ("authServiceUser".trim().equals(condition.getKey())) {
//                    JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(condition.getValue()));
//                    authServiceUserId = jsonObject.getLongValue("id");
//                }
//            }
//            if (authServiceUserId != null && authServiceUserId > 0) {
//                Query totalNumQuery = eruptDao.getEntityManager().createNativeQuery(
//                        "select count(*) as number from s_uses_order as u_order where is_delete = false " + sqlExStr);
//                Query refuseNumQuery = eruptDao.getEntityManager().createNativeQuery(
//                        "select count(*) as number from s_uses_order as u_order where is_delete = false and (u_order.status = 4 or u_order.status = 2) " + sqlExStr);
//                Query successNumQuery = eruptDao.getEntityManager().createNativeQuery(
//                        "select count(*) as number from s_uses_order as u_order where is_delete = false and u_order.status > 4" + sqlExStr);
//
//                Object totalNum = totalNumQuery.getResultList().get(0);
//                totalNum = totalNum == null ? "0" : totalNum;
//                Object refuseNum = refuseNumQuery.getResultList().get(0);
//                refuseNum = refuseNum == null ? "0" : refuseNum;
//                Object successNum = successNumQuery.getResultList().get(0);
//                successNum = successNum == null ? "0" : successNum;
//
//                List<Column> orderColumns = new ArrayList<>();
//                orderColumns.add(Column.builder().value("").colspan(1).build());
//                orderColumns.add(Column.builder().value("总数：" + totalNum).colspan(1).className("text-green").build());
//                orderColumns.add(Column.builder().value("通过：" + successNum).colspan(1).className("text-green").build());
//                orderColumns.add(Column.builder().value("拒绝：" + refuseNum).colspan(1).className("text-red").build());
//                rows.add(Row.builder().columns(orderColumns).build());
//            }
//        }
//
//        return rows;
//    }
//
//
//    /**
//     * 设置订单数据（今日/明日）
//     *
//     * @param list
//     * @param payStatus
//     * @param startTime
//     * @param endTime
//     */
//    public void setDayOrderData(Collection<Map<String, Object>> list,
//                                Boolean payStatus,
//                                String startTime, String endTime, Boolean isPool) {
//        String pageIndexStr = util.getSearchParam("pageIndex", 1);
//        String pageSizeStr = util.getSearchParam("pageSize", 1);
//        pageIndexStr = pageIndexStr == null ? "1" : pageIndexStr;
//        pageSizeStr = pageSizeStr == null ? "10" : pageSizeStr;
//
//        UserOrderByMybatis search = getOrderStatisticParam(payStatus, startTime, endTime, isPool);
//
//        PageHelper.startPage(Integer.parseInt(pageIndexStr), Integer.parseInt(pageSizeStr));
//        com.github.pagehelper.Page<UserOrderByMybatis> userOrderByMybatisList = userOrderByMybatisMapper.selectOrderByDayPay(search);
//        if (userOrderByMybatisList == null || userOrderByMybatisList.size() == 0) {
//            return;
//        }
//        for (UserOrderByMybatis userOrderByMybatis : userOrderByMybatisList) {
//            userOrderByMybatis.setPageIndex(userOrderByMybatisList.getPageNum());
//            userOrderByMybatis.setPageSize(userOrderByMybatisList.getPageSize());
//            userOrderByMybatis.setTotal(userOrderByMybatisList.getTotal());
//            userOrderByMybatis.setTotalPage(userOrderByMybatisList.getPages());
//
//            Map map = JSON.parseObject(JSON.toJSONString(userOrderByMybatis), Map.class);
//
//            if (map.containsKey("payTime")) {
//                map.put("payTime", DateUtil.formatDateTime(DateUtil.date(Long.parseLong(map.get("payTime").toString()))).toString());
//            }
//
//            list.add(map);
//        }
//    }
//
//
//    public List<Row> setOrderStatisticByTodayPay(Boolean payStatus, Integer offset, Boolean isPool) {
//        //行对象
//        List<Row> rows = new ArrayList<>();
//
////        Long businessId = null, channelId = null, serviceEruptUserId = null, rentalUserId = null, authServiceUserId = null,
////                afterServiceUserId = null, overdueServiceUserId = null;
////
////        String rentalUserIdStr = util.getSearchParam("rentalUser", 0);
////        String authServiceUserIdStr = util.getSearchParam("authServiceUser", 1);
////        String afterServiceUserIdStr = util.getSearchParam("afterServiceUser", 1);
////        String overdueServiceUserIdStr = util.getSearchParam("overdueServiceUser", 1);
////        String businessIdStr = util.getSearchParam("business", 1);
////        String channelIdStr = util.getSearchParam("channel", 1);
////        String billTag = util.getSearchParam("billTag", 1);
////
////        authServiceUserId = StringUtils.hasLength(authServiceUserIdStr) ? Long.valueOf(authServiceUserIdStr) : null;
////        afterServiceUserId = StringUtils.hasLength(afterServiceUserIdStr) ? Long.valueOf(afterServiceUserIdStr) : null;
////        overdueServiceUserId = StringUtils.hasLength(overdueServiceUserIdStr) ? Long.valueOf(overdueServiceUserIdStr) : null;
////
////        if (StringUtils.hasLength(businessIdStr)) {
////            businessId = Long.valueOf(businessIdStr);
////        }
////        if (StringUtils.hasLength(channelIdStr)) {
////            channelId = Long.valueOf(channelIdStr);
////        }
////        if (StringUtils.hasLength(rentalUserIdStr)) {
////            rentalUserId = Long.valueOf(rentalUserIdStr);
////        }
////
////        List<Long> ids = rentalUserService.getUserIdBySearch();
////
////        EruptUserByMybatis eruptUserByMybatis = eruptUserByMybatisMapper.selectByPrimaryKey(eruptUserService.getCurrentUid());
////        if (eruptUserByMybatis != null && eruptUserByMybatis.getBusinessId() != null) {
////            businessId = eruptUserByMybatis.getBusinessId();
////        } else if (!eruptUserByMybatis.getIsAdmin()) {
////            //如果不是超管 只能查看自己领取的订单
////            serviceEruptUserId = eruptUserService.getCurrentUid();
////        }
//
//        String startTime, endTime;
//        if (offset == null) {
//            startTime = DateUtil.beginOfDay(new Date()).toString();
//            endTime = DateUtil.endOfDay(new Date()).toString();
//        } else {
//            startTime = DateUtil.offsetDay(DateUtil.beginOfDay(new Date()), offset).toString();
//            endTime = DateUtil.offsetDay(DateUtil.endOfDay(new Date()), offset).toString();
//        }
//        UserOrderByMybatis search = getOrderStatisticParam(payStatus, null, null, isPool);
//        search.setStartTime(startTime);
//        search.setEndTime(endTime);
//
//
////        UserOrderByMybatis search = new UserOrderByMybatis();
////        search.setStartTime(startTime);
////        search.setEndTime(endTime);
////        if (payStatus != null) {
////            search.setStatus(payStatus ? OrderStatus.end.getStatus() : OrderStatus.rent_ing.getStatus());
////        }
////        search.setBusinessId(businessId);
////        search.setAuthServiceId(authServiceUserId);
////        search.setAfterServiceId(afterServiceUserId);
////        search.setOverdueServiceId(overdueServiceUserId);
////        search.setBusinessId(businessId);
////        search.setBusinessId(businessId);
////        search.setServiceEruptUserId(serviceEruptUserId);
////        search.setRentalUserId(rentalUserId);
////        search.setChannelId(channelId);
////        search.setUserIds(ids);
////        search.setIsPool(isPool);
////        if (StringUtils.hasLength(billTag)) {
////            search.setBillTag(Integer.valueOf(billTag));
////        }
//        BigDecimal totalMoney = BigDecimal.ZERO;
//        BigDecimal payMoney = BigDecimal.ZERO;
//        BigDecimal discountsMoney = BigDecimal.ZERO;
//        UserOrderByMybatis userOrderByMybatis = userOrderByMybatisMapper.selectSumByDay(search);
//        if (userOrderByMybatis != null) {
//            totalMoney = userOrderByMybatis.getPrice() == null ? BigDecimal.ZERO : userOrderByMybatis.getPrice();
//            payMoney = userOrderByMybatis.getPayMoney() == null ? BigDecimal.ZERO : userOrderByMybatis.getPayMoney();
//            discountsMoney = userOrderByMybatis.getDiscountsMoney() == null ? BigDecimal.ZERO : userOrderByMybatis.getDiscountsMoney();
//        }
//        //列对象
//        List<Column> totalColumns = new ArrayList<>();
//        totalColumns.add(Column.builder().value("").colspan(1).build());
//        totalColumns.add(Column.builder().value("总金额：" + totalMoney).colspan(1).className("text-green").build());
//        totalColumns.add(Column.builder().value("已收：" + payMoney).colspan(1).className("text-green").build());
//        totalColumns.add(Column.builder().value("优惠：" + discountsMoney).colspan(1).className("text-green").build());
//
//        rows.add(Row.builder().columns(totalColumns).build());
//        return rows;
//    }
//
//
//    private UserOrderByMybatis getOrderStatisticParam(Boolean payStatus, String startTime, String endTime, Boolean isPool) {
//        Long businessId = null, channelId = null, serviceEruptUserId = null, rentalUserId = null, authServiceUserId = null,
//                afterServiceUserId = null, overdueServiceUserId = null;
//
//        String rentalUserIdStr = util.getSearchParam("rentalUser", 0);
//        String businessIdStr = util.getSearchParam("business", 1);
//        String billTag = util.getSearchParam("billTag", 1);
//        String channelIdStr = util.getSearchParam("channel", 1);
//        String authServiceUserIdStr = util.getSearchParam("authServiceUser", 1);
//        String afterServiceUserIdStr = util.getSearchParam("afterServiceUser", 1);
//        String overdueServiceUserIdStr = util.getSearchParam("overdueServiceUser", 1);
//
//        authServiceUserId = StringUtils.hasLength(authServiceUserIdStr) ? Long.valueOf(authServiceUserIdStr) : null;
//        afterServiceUserId = StringUtils.hasLength(afterServiceUserIdStr) ? Long.valueOf(afterServiceUserIdStr) : null;
//        overdueServiceUserId = StringUtils.hasLength(overdueServiceUserIdStr) ? Long.valueOf(overdueServiceUserIdStr) : null;
//
//        if (StringUtils.hasLength(businessIdStr)) {
//            businessId = Long.valueOf(businessIdStr);
//        }
//        if (StringUtils.hasLength(channelIdStr)) {
//            channelId = Long.valueOf(channelIdStr);
//        }
//        if (StringUtils.hasLength(rentalUserIdStr)) {
//            rentalUserId = Long.valueOf(rentalUserIdStr);
//        }
//
//        List<Long> ids = rentalUserService.getUserIdBySearch();
//
//        EruptUserByMybatis eruptUserByMybatis = eruptUserByMybatisMapper.selectByPrimaryKey(eruptUserService.getCurrentUid());
//        if (eruptUserByMybatis != null && eruptUserByMybatis.getBusinessId() != null) {
//            //商户管理员
//            businessId = eruptUserByMybatis.getBusinessId();
//        } else if (!eruptUserByMybatis.getIsAdmin() && !isPool) {
//            //如果不是超管 只能查看自己领取的订单
//            serviceEruptUserId = eruptUserService.getCurrentUid();
//        }
//
//        UserOrderByMybatis search = new UserOrderByMybatis();
//        search.setStartTime(startTime);
//        search.setEndTime(endTime);
//        if (payStatus != null) {
//            search.setStatus(payStatus ? OrderStatus.end.getStatus() : OrderStatus.rent_ing.getStatus());
//        }
//        search.setAuthServiceId(authServiceUserId);
//        search.setAfterServiceId(afterServiceUserId);
//        search.setOverdueServiceId(overdueServiceUserId);
//        search.setBusinessId(businessId);
//        search.setServiceEruptUserId(serviceEruptUserId);
//        search.setChannelId(channelId);
//        search.setRentalUserId(rentalUserId);
//        search.setUserIds(ids);
//        search.setIsPool(isPool);
//        if (StringUtils.hasLength(billTag)) {
//            search.setBillTag(Integer.valueOf(billTag));
//        }
//        return search;
//    }
//
//
//    /**
//     * 根据某个key获取查询条件中的值
//     *
//     * @param conditions
//     * @param key
//     * @return
//     */
//    public Object getConditionValueByKey(List<Condition> conditions, String key) {
//        if (conditions == null || conditions.size() == 0) {
//            return null;
//        }
//        Object value = null;
//        for (Condition condition : conditions) {
//            if (!key.trim().equals(condition.getKey())) {
//                continue;
//            }
//            value = condition.getValue();
//            if (value == null || !StringUtils.hasLength(value.toString())) {
//                continue;
//            }
//            if ("business".trim().equals(key)) {
//                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(value));
//                value = jsonObject.getString("id");
//            } else if ("goods".trim().equals(key)) {
//                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(value));
//                value = jsonObject.getString("id");
//            } else if ("rentalUser".trim().equals(key)) {
//                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(value));
//                value = jsonObject.getString("id");
//            }
//        }
//        return value;
//    }
//
//    /**
//     * 拼接sql语句
//     *
//     * @param conditions
//     * @return
//     */
//    public String getSqlByOrderCondition(List<Condition> conditions, String asName) {
//        if (conditions == null || conditions.size() == 0) {
//            return "";
//        }
//        String sql = "";
////        [
////        {"key":"business","value":{"id":"1","name":"有点贵"}},
////        {"key":"status","value":"0"},
////        {"key":"nowOverdue"},
////        {"key":"hisOverdue"}
////        ]
//        for (Condition condition : conditions) {
//            String key = condition.getKey();
//            Object value = condition.getValue();
//            if (value == null || !StringUtils.hasLength(value.toString())) {
//                continue;
//            }
//
//            if ("userName".trim().equals(key) || "userPhone".trim().equals(key)
//                    || "baoStatus".trim().equals(key) || "userAddress".trim().equals(key)) {
//                continue;
//            }
//
//            if ("business".trim().equals(key)) {
//                key = "business_id";
//                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(value));
//                value = jsonObject.getString("id");
//            } else if ("goods".trim().equals(key)) {
//                key = "goods_id";
//                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(value));
//                value = jsonObject.getString("id");
//            } else if ("rentalUser".trim().equals(key)) {
//                key = "rental_user_id";
//                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(value));
//                value = jsonObject.getString("id");
//            } else if ("channel".trim().equals(key)) {
//                key = "channel_id";
//                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(value));
//                value = jsonObject.getString("id");
//            } else if ("authServiceUser".trim().equals(key)) {
//                key = "auth_service_id";
//                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(value));
//                value = jsonObject.getString("id");
//            } else if ("afterServiceUser".trim().equals(key)) {
//                key = "after_service_id";
//                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(value));
//                value = jsonObject.getString("id");
//            } else if ("overdueServiceUser".trim().equals(key)) {
//                key = "overdue_service_id";
//                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(value));
//                value = jsonObject.getString("id");
//            } else if ("orderId".trim().equals(key)) {
//                key = "id";
//                value = value.toString();
//            } else if ("remark".trim().equals(key)) {
//                value = value.toString();
//                sql = sql + " and " + asName + ".remark = '" + value + "'";
//                continue;
//            } else if ("hasDiscountsMoney".trim().equals(key)) {
//                value = value.toString();
//                if (value.toString().equals("true")) {
//                    sql = sql + " and " + asName + ".discounts_money > 0";
//                }
//                continue;
//            } else if ("orderLocation".trim().equals(key)) {
//                sql = sql + " and " + asName + ".order_location like '%" + value + "%'";
//                continue;
//            }
//
////            else if("userName".trim().equals(key) || "userPhone".trim().equals(key)){
////                key = "rental_user_id";
////                //
////
////                rentalUserByMybatisMapper.selectCountByMobile(,userName)
////
////                sql = sql + " and " + asName + "." + key + " in (" + itemStr + ")";
////            }
//            key = Util.camelToUnderline(key);
//            if ("create_time".trim().equals(key) || "pay_time".trim().equals(key)) {
//                String valueStr = value.toString();
//                valueStr = valueStr.replaceAll("\\[", "");
//                valueStr = valueStr.replaceAll("]", "");
//                sql = sql + " and " + asName + "." + key + " >= '" + valueStr.split(",")[0] + "'";
//                sql = sql + " and " + asName + "." + key + " <= '" + valueStr.split(",")[1] + "'";
//            } else if (JSONArray.isValidArray(value.toString())) {
//                JSONArray jsonArray = JSON.parseArray(value.toString());
//                if (jsonArray.size() > 0) {
//                    String itemStr = null;
//                    for (Object item : jsonArray) {
//                        if (StringUtils.hasLength(itemStr)) {
//                            itemStr = itemStr + "," + item.toString();
//                        } else {
//                            itemStr = item.toString();
//                        }
//                    }
//                    sql = sql + " and " + asName + "." + key + " in (" + itemStr + ")";
//                }
//            } else {
//                sql = sql + " and " + asName + "." + key + " = " + value;
//            }
//        }
//        return sql;
//    }
//
//    /**
//     * 是否是商户列表
//     *
//     * @param className
//     * @param isBusiness
//     * @return
//     */
//    public String getBusinessSql(String className, boolean isBusiness, List<Condition> conditions) {
//        String sql = null;
//        Long businessId = null;
//        EruptUserByMybatis eruptUserByMybatis = eruptUserByMybatisMapper.selectByPrimaryKey(eruptUserService.getCurrentUid());
//        if (eruptUserByMybatis != null && eruptUserByMybatis.getBusinessId() != null) {
//            businessId = eruptUserByMybatis.getBusinessId();
//        }
//        if (businessId != null && businessId > 0) {
//            if (isBusiness) {
//                sql = className + ".id = " + businessId;
//            } else {
//                sql = className + ".business.id = " + businessId;
//            }
//        }
//
//        Iterator<Condition> iterator = conditions.iterator();
//        while (iterator.hasNext()) {
//            Condition condition = iterator.next();
//            if ("userName".trim().equals(condition.getKey())) {
//                iterator.remove();
//            }
//        }
//        List<Long> userIds = rentalUserService.getUserIdBySearch();
//        String userIdStr = null;
//        if (userIds == null || userIds.size() <= 0) {
//            return sql;
//        }
//        userIdStr = org.apache.commons.lang3.StringUtils.join(userIds, ",");
//        if (StringUtils.hasLength(sql)) {
//            sql = sql + " and " + className + ".rentalUser.id in (" + userIdStr + ")";
//        } else {
//            sql = className + ".rentalUser.id in (" + userIdStr + ")";
//        }
//        return sql;
//    }
//
//    /**
//     * 订单列表
//     *
//     * @param className
//     * @return
//     */
//    public String getOrderListSql(String className, List<Condition> conditions) {
//        Iterator<Condition> iterator = conditions.iterator();
//        while (iterator.hasNext()) {
//            Condition condition = iterator.next();
//            if ("userName".trim().equals(condition.getKey()) || "userPhone".trim().equals(condition.getKey())
//                    || "baoStatus".trim().equals(condition.getKey())
//                    || "userAddress".trim().equals(condition.getKey()) || "hasDiscountsMoney".trim().equals(condition.getKey())) {
//                iterator.remove();
//            }
//        }
//
//        String sql = "";
//        EruptUserByMybatis eruptUserByMybatis = eruptUserByMybatisMapper.selectByPrimaryKey(eruptUserService.getCurrentUid());
//        if (eruptUserByMybatis != null && eruptUserByMybatis.getBusinessId() != null) {
//            Long businessId = eruptUserByMybatis.getBusinessId();
//            sql = className + ".business.id = " + businessId;
//        } else if (!eruptUserByMybatis.getIsAdmin() && !className.contains("Pool")) {
//            //如果不是超管 只能查看自己领取的订单
//            sql = "(" + className + ".authServiceUser.id = " + eruptUserService.getCurrentUid() + " or "
//                    + className + ".afterServiceUser.id = " + eruptUserService.getCurrentUid() + " or "
//                    + className + ".overdueServiceUser.id = " + eruptUserService.getCurrentUid() + ")";
//        }
//        String hasDiscountsMoney = util.getSearchParam("hasDiscountsMoney", 0);
//        if (hasDiscountsMoney != null && hasDiscountsMoney.trim().equals("true")) {
//            if (StringUtils.hasLength(sql)) {
//                sql = sql + " and " + className + ".discountsMoney > 0";
//            } else {
//                sql = className + ".discountsMoney  > 0";
//            }
//        }
//
//        List<Long> userIds = rentalUserService.getUserIdBySearch();
//        String userIdStr = null;
//        if (userIds != null && userIds.size() > 0) {
//            userIdStr = org.apache.commons.lang3.StringUtils.join(userIds, ",");
//        }
//        if (StringUtils.hasLength(userIdStr)) {
//            if (StringUtils.hasLength(sql)) {
//                sql = sql + " and " + className + ".rentalUser.id in (" + userIdStr + ")";
//            } else {
//                sql = className + ".rentalUser.id in (" + userIdStr + ")";
//            }
//        }
//        if (StringUtils.hasLength(sql)) {
//            return sql;
//        }
//        return null;
//    }
//
//
//    /**
//     * 设置用户历史订单
//     */
//    public void setUserOrderOverdue(Collection<Map<String, Object>> list) {
//        for (Map<String, Object> stringObjectMap : list) {
//            Long orderId = Long.valueOf(stringObjectMap.get("id").toString());
//            UserOrderByMybatis userOrderByMybatis = userOrderByMybatisMapper.selectByPrimaryKey(orderId);
//            List<UserOrderByMybatis> userOrderByMybatisList = userOrderByMybatisMapper.selectOrderByUser(userOrderByMybatis.getRentalUserId());
//            String info = "";
//            Integer overdueNum = 0, rejectNum = 0, success = 0;
//            if (userOrderByMybatisList != null && userOrderByMybatisList.size() > 0) {
//                for (UserOrderByMybatis orderByMybatis : userOrderByMybatisList) {
//                    if (!orderByMybatis.getHisOverdue()) {
//                        overdueNum++;
//                    }
//                    if (orderByMybatis.getStatus() == OrderStatus.platform_reject.getStatus()) {
//                        rejectNum++;
//                    }
//                    if (orderByMybatis.getStatus() == OrderStatus.end.getStatus()) {
//                        success++;
//                    }
//                }
//            }
//
//            if (overdueNum > 0 || rejectNum > 0) {
//                stringObjectMap.put("userHisOrderStatus", false);
//            } else {
//                stringObjectMap.put("userHisOrderStatus", true);
//            }
//
//            info = userOrderByMybatisList.size() + "笔";
//            info = info + ":逾期笔数(" + overdueNum + ")";
//            info = info + ":完成笔数(" + success + ")";
//            info = info + ":驳回笔数(" + rejectNum + ")";
//            stringObjectMap.put("userHisOrderInfo", info);
//        }
//
//    }
//
//
//    /**
//     * 设置收货信息
//     */
//    public void setReceiveInfo(Collection<Map<String, Object>> list) {
//        for (Map<String, Object> stringObjectMap : list) {
//            Long orderId = Long.valueOf(stringObjectMap.get("id").toString());
//            OrderLogisticsByMybatis orderLogisticsByMybatis = orderLogisticsByMybatisMapper.selectByOrderId(orderId);
//            if (orderLogisticsByMybatis != null) {
//                String info = orderLogisticsByMybatis.getAddressName() + " " + orderLogisticsByMybatis.getAddressPhone() + " " + orderLogisticsByMybatis.getAddressInfo();
//                stringObjectMap.put("receiveInfo", info.replaceAll("-", ""));
//            }
//        }
//    }
//
//    /**
//     * 设置额外信息补充url
//     *
//     * @param list
//     */
//    public void setExInfoUrl(Collection<Map<String, Object>> list) {
//        for (Map<String, Object> stringObjectMap : list) {
//            Long orderId = Long.valueOf(stringObjectMap.get("id").toString());
//            stringObjectMap.put("exInfoUrl", requestUrl + "/perfectInfo.html?id=" + orderId);
//        }
//    }
//
//
//    /**
//     * 预防存在多个用户信息
//     *
//     * @param rentalUserIdentities
//     * @return
//     */
//    public UserIdentity getUserIdentity(Set<UserIdentity> rentalUserIdentities) {
//        if (rentalUserIdentities == null || rentalUserIdentities.size() == 0) {
//            return null;
//        }
//        for (UserIdentity rentalUserIdentity : rentalUserIdentities) {
//            if (StringUtils.hasLength(rentalUserIdentity.getIdCardNumber()) && StringUtils.hasLength(rentalUserIdentity.getIdCardName())) {
//                return rentalUserIdentity;
//            }
//        }
//        return null;
//    }
//
//
//    /**
//     * 修改订单e签宝状态
//     *
//     * @param orderSignByMybatis
//     */
//    @Transactional
//    public void updateSignStatus(OrderSignByMybatis orderSignByMybatis) {
//        try {
//            /**
//             * 查询合同地址
//             */
//            List<String> downloadUrls = new ArrayList<>();
//            if (orderSignByMybatis.getSignPlatform() == null || SignPlatform.esign.getType().intValue() == orderSignByMybatis.getSignPlatform()) {
//                //e签宝
//                OrderSignLog item = eSignUtil.signFlowDetail(orderSignByMybatis.getSignFlowId());
//                if (item != null) {
//                    orderSignByMybatis.setBusinessStatus(item.getBusinessStatus());
//                    orderSignByMybatis.setUserStatus(item.getUserStatus());
//                    orderSignByMybatis.setPlatformStatus(item.getPlatformStatus());
//                    downloadUrls.add(eSignUtil.getDownloadUrl(orderSignByMybatis.getSignFlowId()));
//                    orderSignByMybatisMapper.updateByPrimaryKeySelective(orderSignByMybatis);
//                }
//            } else if (SignPlatform.asign.getType().intValue() == orderSignByMybatis.getSignPlatform()) {
//                ResResult contractRes = rentalDataUtil.downloadContract(orderSignByMybatis.getSignFlowId());
//                if (contractRes.getCode().intValue() == Code.SUCCESS.getCode()) {
//                    JSONArray dataArray = (JSONArray) contractRes.getData();
//                    for (Object o : dataArray) {
//                        downloadUrls.add(o.toString());
//                    }
//                }
//                orderSignByMybatis.setUserStatus(2);
//            }
//
//            if (downloadUrls.size() > 0) {
//                String eSignUrl = null;
//                for (int i = 0; i < downloadUrls.size(); i++) {
//                    String localPath;
//                    String downloadUrl = downloadUrls.get(i);
//                    if (orderSignByMybatis.getSignType() == 1) {
//                        localPath = filePath + "/contract/sign/sign_" + orderSignByMybatis.getOrderId() + "_" + orderSignByMybatis.getSignFlowId() + "_" + i + ".pdf";
//                    } else if (orderSignByMybatis.getSignType() == 2) {
//                        localPath = filePath + "/contract/sign/sign_receipt_" + orderSignByMybatis.getOrderId() + "_" + orderSignByMybatis.getSignFlowId() + ".pdf";
//                    } else {
//                        continue;
//                    }
//                    HttpUtil.downloadFile(downloadUrl, localPath);
//                    if (StringUtils.hasText(eSignUrl)) {
//                        eSignUrl = eSignUrl + "|/" + uCloudUtil.putFile(localPath, null);
//                    } else {
//                        eSignUrl = "/" + uCloudUtil.putFile(localPath, null);
//                    }
//                }
//                orderSignByMybatis.seteSignUrl(eSignUrl);
//            }
//            orderSignByMybatisMapper.updateByPrimaryKeySelective(orderSignByMybatis);
//
//            UserOrderByMybatis updateOrder = new UserOrderByMybatis();
//            updateOrder.setId(orderSignByMybatis.getOrderId());
//            updateOrder.setSignFlowStatus(orderSignByMybatis.getUserStatus());
//            userOrderByMybatisMapper.updateByPrimaryKeySelective(updateOrder);
//
//            if (orderSignByMybatis.getSignType() == 1) {
//                UserOrderByMybatis userOrder = userOrderByMybatisMapper.selectOrderById(orderSignByMybatis.getOrderId());
//                if (updateOrder.getSignFlowStatus() == 2 && userOrder.getBusinessId() != null) {
//                    BusinessByMybatis business = businessByMybatisMapper.selectByPrimaryKey(userOrder.getBusinessId());
//                    //签署成功后 扣除风控余额
//                    AddCBalanceVo addCBalanceVo = new AddCBalanceVo();
//                    addCBalanceVo.setNumber(business.getReportUnitBySign());
//                    addCBalanceVo.setBalanceType(BusinessBalanceType.credit.getStatus());
//                    addCBalanceVo.setIsAdd(false);
//                    addCBalanceVo.setRentalUserId(userOrder.getRentalUserId());
//                    addCBalanceVo.setUseType(BusinessBalanceUseType.contract_sign.getType());
//                    addCBalanceVo.setOrderId(userOrder.getId());
//                    businessService.updateCBalance(addCBalanceVo, userOrder.getBusinessId());
//                }
//
//                if (userOrder.getGoodsType() == 2) {
//                    /**
//                     * 虚拟物品增加签收单的合同签署
//                     */
//                    if (orderSignByMybatis.getSignPlatform() == null || SignPlatform.esign.getType().intValue() == orderSignByMybatis.getSignPlatform()) {
//                        ResResult resResult = eSignUtil.createSignByReceipt(orderSignByMybatis.getOrderId());
//                        if (resResult.getCode().intValue() == Code.SUCCESS.getCode().intValue()) {
//                            updateOrder.setStatus(OrderStatus.wait_receive.getStatus());
//                            userOrderByMybatisMapper.updateByPrimaryKeySelective(updateOrder);
//                            eSignService.addSignLog(resResult.getData().toString(), userOrder.getId(), userOrder.getRentalUser_mobile(), 2);
//                        }
//                    } else if (SignPlatform.asign.getType().intValue() == orderSignByMybatis.getSignPlatform()) {
//                        Order dbOrder = eruptDao.queryEntity(Order.class, "id = :id", new HashMap<String, Object>(1) {
//                            {
//                                this.put("id", orderSignByMybatis.getOrderId());
//                            }
//                        });
//                        ResResult resResult = rentalDataUtil.createSignContract(dbOrder, ContractType.receipt_form);
//                        if (resResult == null || resResult.getCode().intValue() != Code.SUCCESS.getCode().intValue()) {
//                            return;
//                        }
//                        JSONObject jsonObject = JSON.parseObject(resResult.getData().toString());
//                        if (jsonObject.containsKey("signUser")) {
//                            JSONArray signUsers = jsonObject.getJSONArray("signUser");
//                            for (Object signUser : signUsers) {
//                                JSONObject ItemSignUser = JSON.parseObject(signUser.toString());
//                                if (ItemSignUser.containsKey("mobile") || ItemSignUser.getString("mobile").trim().equals(dbOrder.getRentalUser().getMobile())) {
//                                    updateOrder.setStatus(OrderStatus.wait_receive.getStatus());
//                                    userOrderByMybatisMapper.updateByPrimaryKeySelective(updateOrder);
//                                    eSignService.addSignLogByASign(jsonObject.getString("contractNo"), dbOrder.getId(), ItemSignUser.getString("signUrl"), 2);
//                                }
//                            }
//                        }
//                    }
//                }
//            } else {
//                /**
//                 * 插入权益
//                 */
//                eSignService.addCardPasswordToOrder(orderSignByMybatis.getOrderId());
//
//                /**
//                 * 物流签收后操作
//                 */
//                logisticsSignature(orderSignByMybatis.getOrderId());
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            log.error(Util.GetErrorDetails(e));
//        }
//    }
//
//}
